
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int n = s.size();
        int mp[130] = { 0 };
        int j = 0;
        int ma = 0;
        int i = 0;
        for (auto x : s) {
            mp[x]++;
            while (mp[x] >= 2) {
                mp[s[j++]]--;
            }
            ma = max(ma, i - j + 1);
            i++;
        }
        return ma;
    }
};